package com.qdlc.p2p.manage.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;

import com.opensymphony.xwork2.ModelDriven;
import com.qdlc.p2p.biz.service.AccountLogService;
import com.qdlc.p2p.biz.util.excel.ExcelUtils;
import com.qdlc.p2p.biz.util.excel.JsGridReportBase;
import com.qdlc.p2p.biz.util.excel.TableData;
import com.qdlc.p2p.biz.web.action.BaseAction;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.model.AccountLogModel;

public class ManageAccountLogAction extends BaseAction<AccountLogModel> implements ModelDriven<AccountLogModel> {

	@Resource
	private AccountLogService accountLogService;

	private Map<String, Object> data;

	/**
	 * 资金记录列表页面
	 * 
	 * @return
	 * @throws Exception
	 */
	@Action("/modules/account/accountlog/accountLogManager")
	public String accountLogManager() throws Exception {
		return "accountLogManager";
	}

	/**
	 * 资金记录列表
	 * 
	 * @return
	 * @throws Exception
	 */
	@Action("/modules/account/accountlog/accountLogList")
	public void accountLogList() throws Exception {
		data = new HashMap<String, Object>();
		int pageNumber = paramInt("page"); // 当前页数
		int pageSize = paramInt("rows"); // 每页每页总数
		PageDataList<AccountLogModel> accountLogList = accountLogService.accountLogList(model, pageNumber, pageSize);
		data.put("total", accountLogList.getPage().getTotal()); // 总行数
		data.put("rows", accountLogList.getList()); // 集合对象
		printJson(getStringOfJpaObj(data));
	}
	
	/**
	 * 导出报表
	 * 
	 * @throws Exception
	 */
	@Action("/modules/account/accountlog/exportExcelAccountLog")
	public void exportExcelAccountLog() throws Exception {

		// 记录取得
		List<AccountLogModel> list = accountLogService.accountLogList(model, 1, 5000).getList();

		String title = "资金日志Excel表";

		String[] hearders = new String[] { "编号", "用户姓名","用户名", "类型", "账户总额(元)", "操作金额(元)", "可用金额(元)", "冻结金额(元)", "待收金额(元)", "交易对方名称", "备注", "添加时间", "添加IP" };// 表头数组
		String[] fields = new String[] { "id","realName", "userName", "type", "total", "moneyString", "useMoneyString", "noUseMoneyString", "collectionString", "toUserName", "remark", "addTime", "addIp" };// 对象属性数组
		TableData td = ExcelUtils.createTableData(list, ExcelUtils.createTableHeader(hearders), fields);
		JsGridReportBase report = new JsGridReportBase(request, response);
		report.exportToExcel(title, getOperator().getUserName(), td);
	}	

}
